package ExceptionDemo;

public class text {

    public static void main(String[] args) {
        BankService bankService = new BankService();

        // 测试正常转账
        testTransfer(bankService, "A001", "A002", 200.0);

        // 测试余额不足
        testTransfer(bankService, "A002", "A001", 600.0);

        // 测试转账金额为负
        testTransfer(bankService, "A001", "A002", -100.0);

        // 测试账户不存在
        testTransfer(bankService, "A999", "A001", 100.0);
    }

    private static void testTransfer(BankService bankService, String from, String to, double amount) {
        try {
            System.out.println("\n尝试转账: 从 " + from + " 到 " + to + " 金额: " + amount);
            bankService.transfer(from, to, amount);
            System.out.println("当前账户余额: A001=" + bankService.getBalance("A001") +
                    ", A002=" + bankService.getBalance("A002"));
        } catch (InsufficientBalanceException | InvalidAmountException | AccountNotFoundException e) {
            System.err.println("转账失败: " + e.getMessage());
            LoggerUtil.logError("转账失败", e);
        } finally {
            System.out.println("操作完成");
        }
    }
}
